/*
 * Copyright (c) 2012 Sean Connelly
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

var assert = require('../assert.js').init();
var ratio = require('../../src/js/ratio.js');

exports.run = function(root_dir, test_dir, test_name) {

		assert.that('basic createInt functionality',
			ratio.createInt(123).num() == 123);

		assert.that('basic createDec functionality',
			ratio.createDec('123').num() == 123);

		assert.that('basic createBase functionality',
			ratio.createBase('abcd', 16) == 0xabcd);

		assert.that('basic createCopy functionality',
			ratio.createCopy(ratio.createInt(345)).num() == 345);

		assert.that('small addition',
			ratio.createInt(23).add(ratio.createInt(34)).num() == 57);

		assert.that('small subtraction',
			ratio.createInt(57).sub(ratio.createInt(23)).num() == 34);

		assert.that('equal subtraction',
			ratio.createInt(23).sub(ratio.createInt(23)).num() == 0);

		assert.that('toString short',
			ratio.createInt(23).toString() === '23');

		assert.that('toString divisble by ten',
			ratio.createInt(2300).toString() == '2300');

		assert.that('small multiply',
			ratio.createInt(234).mul(ratio.createInt(456)).num() == 234 * 456);

		assert.that('small division',
			ratio.createInt(144).div(ratio.createInt(12)).num() == 12);

		assert.that('small modular',
			ratio.createInt(457).mod(ratio.createInt(50)).num() == 7);

		assert.that('negative result',
			ratio.createInt(20).sub(ratio.createInt(30)).num() == -10);

		assert.that('negative multiply',
			ratio.createInt(123).mul(ratio.createInt(-456)).num() == 123 * -456);

		assert.that('createCopy works',
			ratio.createCopy(ratio.createInt(3)).add(ratio.createInt(2)).num() == 5);

		return assert.result();
	};
